<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改合同管理')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
    <th:block th:include="include :: bootstrap-editable-css" />
    <style>
        .fa-search{
            position: relative;
            top: -25px;
        }
        .inputInfo{
            padding-left: inherit;
        }
    </style>
</head>
<body class="white-bg">
    <ul class="nav nav-tabs">
        <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true"> 基本信息</a>
        </li>
        <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">清单列表</a>
        </li>
        <li class=""><a data-toggle="tab" href="#tab-3" aria-expanded="false">附件列表</a>
        </li>
    </ul>
    <div class="tab-content">
        <!--   基本信息    -->
        <div id="tab-1" class="tab-pane active">
            <div class="panel-body">
                <form class="form-horizontal m" id="form-contract-edit" th:object="${contract}">
                    <input name="contractId" th:field="*{contractId}" type="hidden">
                    <h4 class="form-header h4">基本信息</h4>
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">合同名称：</label>
                                <div class="col-sm-10">
                                    <input name="name" th:field="*{name}" readonly  class="form-control" type="text">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">有效开始时间：</label>
                                <div class="col-sm-8">
                                    <div class="input-group date">
                                        <input name="startTime" readonly  th:value="${#dates.format(contract.startTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">有效结束时间：</label>
                                <div class="col-sm-8">
                                    <div class="input-group date">
                                        <input name="endTime" readonly  th:value="${#dates.format(contract.endTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="form-group hidden">
                        <label class="col-sm-4 control-label">合同类型：</label>
                        <input name="contractType" readonly  th:value="*{contractType}"  id="contractType" type="hidden">
                    </div>



                    <h4 class="form-header h4">甲乙基本信息</h4>
                    <div class="row">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">甲方名称：</label>
                                <div class="col-sm-8">
                                    <input name="owner" readonly  th:field="*{owner}" class="form-control inputInfo" type="text" >
                                    <i class="fa fa-search"></i>
                                    </input>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">乙方名称：</label>
                                <div class="col-sm-8">
                                    <input name="buy" readonly   th:field="*{buy}" class="form-control inputInfo" type="text"  >
                                    <i class="fa fa-search"></i>
                                    </input>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">甲方联系人：</label>
                                <div class="col-sm-8">
                                    <input name="ownerName" th:field="*{ownerName}" class="form-control" readonly type="text">
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">乙方联系人：</label>
                                <div class="col-sm-8">
                                    <input name="buyName" th:field="*{buyName}" class="form-control" readonly  type="text">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">甲方联系电话：</label>
                                <div class="col-sm-8">
                                    <input name="ownerPhone"  th:field="*{ownerPhone}" class="form-control" readonly  type="text">
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">乙方联系电话：</label>
                                <div class="col-sm-8">
                                    <input name="buyPhone" th:field="*{buyPhone}" class="form-control" readonly  type="text">
                                </div>
                            </div>
                        </div>
                    </div>


                    <div class="row">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">甲方地址：</label>
                                <div class="col-sm-8">
                                    <input name="ownerAddress" th:field="*{ownerAddress}" class="form-control" readonly  type="text">
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">乙方地址：</label>
                                <div class="col-sm-8">
                                    <input name="buyAddress" th:field="*{buyAddress}" class="form-control" readonly type="text">
                                </div>
                            </div>
                        </div>
                    </div>




                    <div class="form-group hidden">
                        <label class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-8">
                            <select name="status" class="form-control m-b" th:with="type=${@dict.getType('b_contrack_status')}" >
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                    <h4 class="form-header h4">合同内容</h4>
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">合同内容：</label>
                                <div class="col-sm-10">
                                    <input type="hidden" class="form-control" th:field="*{content}">
                                    <div class="summernote" id="content" readonly ></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">备注：</label>
                                <div class="col-sm-10">
                                    <input name="remark" readonly  th:field="*{remark}" class="form-control" type="text">
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <!--   end 基本信息    -->

        <!--   清单列表    -->
        <div id="tab-2" class="tab-pane">
            <div class="panel-body">
                <div class="btn-group-sm hidden" id="toolbar" role="group" >
                    <a class="btn btn-success" onclick="chooseProduct()" >
                        <i class="fa fa-plus"></i> 添加
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="removeQingDan()">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table-qingdan"></table>
                </div>
            </div>
        </div>
        <!--   end清单列表    -->

        <!--   附件列表    -->
        <div id="tab-3" class="tab-pane">
            <div class="panel-body">
                <div class="btn-group-sm hidden" id="toolbar2" role="group">
                    <a class="btn btn-success" onclick="addContractFile()" >
                        <i class="fa fa-plus"></i> 添加
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="removeRow()">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table-file"></table>
                </div>
            </div>
        </div>
        <!--   end附件列表    -->
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <th:block th:include="include :: bootstrap-table-editable-js" />
    <script th:inline="javascript">
        var typeDatas = [[${@dict.getType('b_file_type')}]];
        var suffixDatas = [[${@dict.getType('b_contrack_file_suffix')}]];
        var prefix = ctx + "contract/contract";
        var modelType="edit";//
        var contractType=localStorage.getItem("contractType");
        var contractId = [[${contract.contractId}]];
        $("#form-contract-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var data =  $('#form-contract-edit').serialize();
                data=data+"&params[qingdan]="+getAllQingDanData()+"&params[contractFile]="+getAllContractFileData();
                log.log(data);
                $.operate.save(prefix + "/edit",data);
            }
        }

        $("input[name='startTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='endTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='createDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    dialogsInBody: true,
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/upload",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });
    </script>
    <script th:src="@{/js/contract/contractProduct/congractProduct.js}"></script>
    <script th:src="@{/js/contract/contractFile/contractFile.js}"></script>
    <script th:src="@{/js/contract/chooseParter.js}"></script>
</body>
</html>
